package com.fitsoftwareprocess.mobimap.dto;

import java.io.Serializable;
import java.util.Hashtable;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

public class Coordinate implements Serializable {
//	private static double _longitude;
   // private static double _latitude;
	
    public static  double _longitude=0;
	public static double _latitude=0;

    public Coordinate()
    {
        _longitude = 0;
        _latitude = 0;
    }

    public Coordinate(Coordinate p)
    {
        this._latitude = p._latitude;
        this._longitude = p._longitude;
    }

    public Coordinate(double latitude,double longitude)
    {
        this._latitude = latitude;
        this._longitude = longitude;
    }

    public Boolean Equals(Object obj)
    {
        Coordinate p = (Coordinate)obj;
        if (p._longitude == this._longitude && p._latitude == this._latitude)
            return true;
        return false;
    }

    public static double Distance(Coordinate p1, Coordinate p2)
    {
        double theta = p1._longitude - p2._longitude;
        double dist = Math.sin(deg2rad(p1._latitude)) * Math.sin(deg2rad(p2._latitude)) + Math.cos(deg2rad(p1._latitude)) * Math.cos(deg2rad(p2._latitude)) * Math.cos(deg2rad(theta));
        dist = Math.acos(dist);
        dist = rad2deg(dist);
        dist = dist * 60 * 1.1515;
        dist = dist * 1.609344;

        return (dist);
    }

    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //::  This function converts decimal degrees to radians             :::
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    public static double deg2rad(double deg)
    {
        return (deg * Math.PI / 180.0);
    }

    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //::  This function converts radians to decimal degrees             :::
    //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    public static double rad2deg(double rad)
    {
        return (rad / Math.PI * 180.0);
    }
    
    public static double CalculateAngle(Coordinate A, Coordinate B, Coordinate C)
    {
    	double ab = CalculateDistance(A, B);
    	double ac = CalculateDistance(A, C);
    	double bc = CalculateDistance(B, C);
    	if(ab == 0 || ac == 0)
    		return 0;
    	return Math.acos((Math.pow(ab,2) + Math.pow(bc,2) - Math.pow(ac,2))/(2*ab*bc));
    }
    //Distance tren 1 mp
    public static double CalculateDistance(Coordinate A, Coordinate B)
    {
    	return Math.sqrt(Math.pow(B.get_longitude()-A.get_longitude(),2) + Math.pow(B.get_latitude()-A.get_latitude(),2));
    }

	public double get_longitude() {
		return _longitude;
	}

	public void set_longitude(double _longitude) {
		this._longitude = _longitude;
	}

	public double get_latitude() {
		return _latitude;
	}

	public void set_latitude(double _latitude) {
		this._latitude = _latitude;
	}

//	public Object getProperty(int arg0) {
//		switch(arg0)
//		{
//		case 0:
//			return _longitude;
//		case 1:
//			return _latitude;
//		}
//		return null;
//	}
//
//	public int getPropertyCount() {
//		// TODO Auto-generated method stub
//		return 2;
//	}
//
//	public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
//		switch(index)
//        {
//        case 0:
//            info.type = Double.class;
//            info.name = "CategoryId";
//            break;
//        case 1:
//            info.type = Double.class;
//            info.name = "Name";
//            break;        
//        default:break;
//        }
//	}
//
//	public void setProperty(int index, Object value) {
//		 switch(index)
//	        {
//	        case 0:
//	            _longitude = Double.parseDouble(value.toString());
//	            break;
//	        case 1:
//	            _latitude = Double.parseDouble(value.toString());
//	            break;
//	        default:
//	            break;
//	        }
//	}
}

